package com.ehome.poct.backend.controller;

import com.ehome.poct.base.api.dto.banner.BannerAbleDTO;
import com.ehome.poct.base.api.dto.banner.BannerDTO;
import com.ehome.poct.base.api.dto.banner.BannerDataDTO;
import com.ehome.poct.base.api.dto.banner.BannerPageDTO;
import com.ehome.poct.base.api.feign.BannerClient;
import com.ehome.poct.base.api.vo.banner.BannerDataVO;
import com.ehome.poct.base.api.vo.banner.BannerDictDataVO;
import com.ehome.poct.base.api.vo.banner.BannerInfoPageVO;
import com.ehome.poct.base.api.vo.banner.BannerInfoVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:轮播图配置
 * @author: muqiu
 * @time: 2022/3/8 10:22
 */
@Api(tags = "广告页配置")
@ApiSupport(author = "muqiu")
@RequestMapping("/banner")
@RestController
public class BannerMgrController {

    @Autowired
    private BannerClient bannerClient;

    @ApiOperation("广告新增")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping("/add")
    public Boolean addBanner(@RequestBody BannerDTO bannerDTO){
        return bannerClient.add(bannerDTO);
    }

    @ApiOperation("广告筛选条件下拉框")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/dictData")
    public List<BannerDictDataVO> dictData(){
        return bannerClient.getDictData();
    }

    @ApiOperation("广告列表")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping("/list")
    public BannerInfoPageVO getBanners(@RequestBody BannerPageDTO bannerPageDTO){
        return bannerClient.getBanners(bannerPageDTO);
    }

    /**
     * 编辑回显
     *
     * @return
     */
    @ApiOperation("编辑回显")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/{id}")
    public BannerInfoVO getById(@PathVariable(value = "id")Long id) {
        return bannerClient.getById(id);
    }

    /**
     * 广告禁用和启用
     * @param ableDTO
     * @return
     */
    @ApiOperation("广告禁用和启用（0禁用、1启用）")
    @ApiOperationSupport(author = "muqiu")
    @PutMapping("/disable")
    public Boolean disable(@RequestBody BannerAbleDTO ableDTO) {
        return bannerClient.disable(ableDTO);
    }

    /**
     * 广告删除
     * @param id
     * @return
     */
    @ApiOperation("广告删除")
    @ApiOperationSupport(author = "muqiu")
    @DeleteMapping("/delete/{id}")
    public Boolean delete(@PathVariable(value = "id") Long id) {
        return bannerClient.delete(id);
    }

    /**
     * 查看数据
     * @param bannerDataDTO
     * @return
     */
    @ApiOperation("查看数据")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping("/data")
    public BannerDataVO getData(@RequestBody BannerDataDTO bannerDataDTO) {
        return bannerClient.getData(bannerDataDTO);
    }
}
